const Pool = require("pg").Pool;

const pool = new Pool({
  user: "postgres",
  password: "qwe!@#",
  host: "localhost",
  port: 15432,
  database: "Eng",
});
function query(sql, res) {
  // 查询
  pool.connect(function (err, client, done) {
    if (err) {
      return console.error("数据库连接出错", err);
    }
    console.log(`${sql}`);
    client.query(`${sql}`, function (error, result) {
      done();
      if (error) {
        res.status(500).json({ error: error });
      } else {
        if(result.command === 'UPDATE'){
          res.json({ info: 'success' });
          return;
        }
        res.json({ info: result.rows });
      }
    });
  });
}
module.exports = { pool, query };
